/*
 * @Author: wang.xiao 
 * @Date: 2017-10-18 11:06:39
 */
class SceneManager extends egret.Sprite{
	// 声明场景控制器的单例
	private static instance: SceneManager;
	// 开始场景
	private gameStartPanel: GameStartPanel;
	// 游戏中场景
	public gamePlayingPanel: GamePlayingPanel; 

	public constructor() {
		super();
		// 初始化
		this.init();
	}
	private init() {
		this.gameStartPanel = new GameStartPanel();
		this.gamePlayingPanel = new GamePlayingPanel();
		// 将开始场景添加到显示列表
		// this.addChild(this.gameStartPanel);
		this.addChild(this.gamePlayingPanel);

		// this.gamePlayingPanel.start();

				
		// 开始场景的配置
		this.gameStartPanel.start();
		// 添加监听事件
		this.addEventListener(ChangeSceneEvent.CHANGE_SCENE_EVENT,this.onChangeScene,this);
		
	}
	// 实例化单例方法
	public static getInstance(): SceneManager{
		if(SceneManager.instance == null){
			SceneManager.instance = new SceneManager();
		}
		return SceneManager.instance;
	}
	// 监听自定义事件后的响应事件
	public onChangeScene(e: ChangeSceneEvent){
		// 释放前一场景资源
		e.obj.end();
		// 移除所有子元素
		// this.removeChildren();

		this.removeChild(this.gameStartPanel);

		// 判断事件类型,响应不同处理
		switch(e.eventType){
			case GameStartPanel.GAME_START:{
				this.gameStartPanel.start();
				this.addChild(this.gameStartPanel);
				break;
			}
			case GamePlayingPanel.CHANGEPANEL:{
				// this.gamePlayingPanel.start();
				this.addChild(this.gamePlayingPanel);
				break;
			}
			default:
				break;
		}
	}
}